package com.example.dbsample.model.vo;

import com.example.dbsample.model.enums.CommonErrorCodeEnum;
import com.example.dbsample.util.date.DateTimeUtils;
import lombok.Data;

@Data
public class PHAIResponse<T> {
    private static final long serialVerssionUID = 1212131313L;

    //private static final PHAIResponse TIMEOUT = new PHAIResponse("510", "timeout");
    //private static final PHAIResponse JSON_ERR = new PHAIResponse("511", "");
    private String code = CommonErrorCodeEnum.SUCCESS.getCode();
    private String message = CommonErrorCodeEnum.SUCCESS.getMsg();
    private T data;
    // 接口日志连接追踪id
    private String traceId;
    // 接口响应时间戳
    private String timestamp = DateTimeUtils.formatNowWithMillis();
    // 接口响应耗时 单位ms
    private long costMS;

    public static <T> PHAIResponse<T> success() {
        PHAIResponse<T> response = new PHAIResponse<>();
        response.setCode(CommonErrorCodeEnum.SUCCESS.getCode());
        response.setMessage(CommonErrorCodeEnum.SUCCESS.getMsg());
        return response;
    }


    public static <T> PHAIResponse<T> success(T data) {
        PHAIResponse<T> response = new PHAIResponse<>();
        response.setCode(CommonErrorCodeEnum.SUCCESS.getCode());
        response.setMessage(CommonErrorCodeEnum.SUCCESS.getMsg());
        response.setData(data);
        return response;
    }


    public static <T> PHAIResponse<T> fail(String code, String message) {
        PHAIResponse<T> response = new PHAIResponse<>();
        response.setCode(code);
        response.setMessage(message);
        return response;
    }
}
